package org.example;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;


@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Thread)
@Fork(1)
@Warmup(iterations = 3)
@Measurement(iterations = 10)
public class JMHMain {

    private long res;

    @Benchmark
    public void testFb() {
        res = fb(35);
    }

    public long fb(long n) {
        if (n == 0 || n == 1) {
            return 1;
        } else {
            return fb(n - 1) + fb(n - 2);
        }
    }

    @TearDown(Level.Iteration)
    public void showRes() {
        System.out.printf("f35=%d\t耗时：", res);
    }

    public static void main(String[] args) throws Exception {
        Options opt = new OptionsBuilder()
                .include(JMHMain.class.getSimpleName())
                .build();
        new Runner(opt).run();
    }
}